#!/bin/bash
# 程序说明：Bash脚本，安装vim的配置
# 使用环境：
#   unix系统都可以
#   要求安装git    
# 作者：sidpku(cnqdcyq@163.com)
# 时间：2021/8/14

# 定义常量
Me=$USER     # 用户名
MyHome=$HOME # 用户的家目录 
GitRepoDir=$(pwd)
VIMRC=$HOME/.vimrc
SnippetsURL='https://gitee.com/sid886/my-snippets.git'
# update submodules
git submodule update --init

# if vimrc is exist,backup,then copy this vimrc to home
if [[ -f ~/.vimrc ]];then
	cp ~/.vimrc ~/.vimrc.backup
fi
cp ./.vimrc ~/.vimrc

# check if vundle is installed
if [[ -d ~/.vim/bundle/Vundle.vim ]];then
	echo "vundle has been installed"
else
	git clone https://gitclone.com/github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
fi

# change source dir for plugin install
sed -i "s#LOCALPATH#$GitRepoDir#g" $VIMRC

# install Plugin
vim +PluginInstall +qall
# git init for snippets
SnippetsDir="$HOME/.vim/UltiSnips"
if [[ -d "$SnippetsDir/.git" ]];then
	echo "Git repo for snippets has been set"
else
	cd $SnippetsDir && git init && git remote add origin $SnippetsURL 
	cd $GitRepoDir
fi
